import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class GUIclass extends JFrame {
	JPanel myPanel;
	JButton buttonWrite;
	static JTextField textFieldWithText;
	JButton buttonRead;
	FileClass myClass;
	File myFile = new File("readMe.txt");
		
	private static final long serialVersionUID = 4395228632732076396L;

	
	GUIclass() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		myClass = new FileClass();
				
		myPanel = new JPanel();
		myPanel.setLayout(null);

		
		buttonWrite = new JButton("Write");
		buttonWrite.setBounds(15, 80, 100, 30);
		myPanel.add(buttonWrite);
		buttonWrite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (textFieldWithText.getText().equals("")) {
					JOptionPane.showMessageDialog(null, "Type your text here !");
				}
				else
					myClass.writeFile(textFieldWithText.getText());
				}	
			});
		
		
		textFieldWithText = new JTextField("My text is here!");
		textFieldWithText.setBounds(5, 10, 375, 30);
		myPanel.add(textFieldWithText);

		buttonRead = new JButton("Read");
		buttonRead.setBounds(270, 80, 100, 30);
		myPanel.add(buttonRead);
		buttonRead.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e2) {
					myClass.readFile();
				}	
			});
		
		getContentPane().add(myPanel);		
		setPreferredSize(new Dimension(400, 160));
	}

	
	public static void setTextFieldWithText(String str) {
		textFieldWithText.setText(str);
	}

	
	public void runMyFrame() {
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
    				JFrame.setDefaultLookAndFeelDecorated(true);
    				pack();
    				setLocationRelativeTo(null);
    				setVisible(true);
    			}
            });
    }
	
	
	

}
